package app.netant.book.xqishu;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class XqishuDetail extends BaseDetail {

	public XqishuDetail(String netSite) {
		super(netSite);
		this.preHref = "http://www.xqishu.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".wrap .show .showBox .detail .detail_info .detail_right h1");
		if(parts.size()>0){
			String title = parts.get(0).text().trim();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title);
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".wrap .show .showBox .detail .detail_info .detail_right ul li");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx).trim();
				String tagValue = tags.substring(idx+1).trim();
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".wrap .show .showBox.mt20 .showInfo");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".wrap .show .showBox.mt20 .showDown ul li a.downButton");
		for(int i=0;i<parts.size();i++){
			String txt = parts.get(i).text();
			if(txt.indexOf("下载")>0){
				String href = parts.get(i).attr("href");
				System.out.println("【Href】:"+href);
				this.entity.setDownPath(href);
				
				int idx = href.lastIndexOf(".");
				if(idx>0){
					this.entity.setNovelFullName(this.entity.getNovelName()+href.substring(idx));
				}
				
				break;
			}
			
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select(".wrap.position span a");
		if(parts.size()>2){
			String type = parts.get(2).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		XqishuDetail detail = new XqishuDetail("http://www.xqishu.com/txt/52513.html");
		detail.test();
	}



}
